package com.chisheng.mapper;

import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import java.util.Random;
import java.util.UUID;

@Repository
public class UserDao {

    private final JdbcTemplate jdbcTemplate;

    public UserDao(JdbcTemplate jdbcTemplate) {
        this.jdbcTemplate = jdbcTemplate;
    }

    @SuppressWarnings("all")  /* Unable to resolve column 'username' */
    public boolean randomInsertUser() {
        String insertSQL = "insert into t_user(username, age) values(?, ?)";
        return jdbcTemplate.update(insertSQL, UUID.randomUUID().toString().replace("-", "")
                .substring(0, 10), new Random().nextInt(100)) > 0;
    }

}
